// component/career-selector.ts
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    initValue: { // 属性名
      type: null,
      value: ""
    },
    type: { 
      /**
       * orderType   deviceType
       */
      type: String,
      value: ""
    },
    height: { // 属性名
      type: String,
      value: "30px"
    },
  },
  observers:{
    initValue:function(){
        if(!this.data.initValue){
          this.setData({
            currentSelectedIndex: 0,
            currentSelectedValue: this.data.selectOptions[0],
            dispValue:this.data.selectOptions[0],
          })
        }
        else{
          this.data.selectOptions.forEach((item,index)=>{
            if(item == this.data.initValue){
              this.setData({
                currentSelectedIndex: index,
                currentSelectedValue: this.data.selectOptions[index],
                dispValue:this.data.initValue
              })
            }
          })
        }
    },
    type:function(){
       if(this.data.type=="orderType"){
        this.setData({
          selectOptions:this.data.orderTypeOptions
        })
       }
       else  if(this.data.type=="orderStatusForProc"){
        this.setData({
          selectOptions:this.data.orderStatusOptionsForProc,
          zeroIndexUseFlag:true
        })
       }
       else  if(this.data.type=="deviceType"){
        this.setData({
          selectOptions:this.data.deviceTypeOptions
        })
       }
       else  if(this.data.type=="workOrderPriority"){
        this.setData({
          selectOptions:this.data.workOrderPriorityOptions
        })
       }
       else  if(this.data.type=="orderStatus"){
        this.setData({
          selectOptions:this.data.orderStatusOptions,
        })
       }
       this.setData({
        currentSelectedIndex: 0,
        currentSelectedValue:this.data.selectOptions[0],
        dispValue:this.data.selectOptions[0]
      })
    }
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () {
     },
    hide: function () { },
    resize: function () { },
  },
  /**
   * 组件的初始数据
   */
  data: {
    selectOptions:["请选择"],
    currentSelectedIndex:0,
    currentSelectedValue:"",
    zeroIndexUseFlag:false,
    dispValue:"请选择",
    orderTypeOptions:["请选择","设备故障","设备掉线","设备清理"],
    deviceTypeOptions:["请选择","电表","水表","蒸汽表"],
    workOrderPriorityOptions:["请选择","紧急","高","中","低"],
    receiveTypeOptions:["请选择","指定人员","报名选择"],
    orderStatusOptions:["请选择","待处理","处理中","处理完成","关闭"],
    orderStatusOptionsForProc:["待处理","处理中","处理完成","关闭"]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onSupportChange: function(e:any){
      this.setData({
        currentSelectedIndex: e.detail.value,
        currentSelectedValue: this.data.selectOptions[e.detail.value],
      })
      //提交数据到父页面
      if(this.data.zeroIndexUseFlag || this.data.currentSelectedIndex > 0){
        this.triggerEvent('selectorChanged', {value:this.data.currentSelectedValue}) 
      }
      else{
        this.triggerEvent('selectorChanged', {value:""}) 
      }
   
    },
    onSupportColumnChange: function(e:any){
      console.info(e.detail)
      // //如果是第一级变了，更改第一级信息，并且获取第二级信息
      // if (e.detail.column == 0){
      //   this.getSelectOptions(e.detail.value)
      //   this.setData({
      //     currentSelectedIndex: [e.detail.value,0],
      //     currentSelectedValue: [this.data.OrgAllData[e.detail.value].text, this.data.selectOptions[1][0]],
      //   })

      // }
      // else{
      //   this.setData({
      //     'currentSelectedIndex[1]': e.detail.value,
      //     'currentSelectedValue[1]': this.data.selectOptions[1][e.detail.value],
      //   })
      
    },
    clickMe(e:any){
      console.log("触发点击事件")
    }
  
  }
})